Attribute VB_Name = "modNAMAG"
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long

Private Const LB_FINDSTRINGEXACT = &H1A2

Public Function AddToListbox(strListBItem As String, LB As ListBox) As Boolean

    Dim lngListIndex As Long
    
    ' lngListIndex is the ListIndex if the item is found
    lngListIndex = SendMessage(LB.hwnd, LB_FINDSTRINGEXACT, -1, ByVal strListBItem)
    If lngListIndex = -1 Then
    AddToListbox = False
        LB.AddItem strListBItem
    Else
    AddToListbox = True
       ' MsgBox strListBItem & " is already in the Listbox"
        Exit Function
    End If
End Function

Public Function TrimAlpha(ByVal myText As String) As String
TrimAlpha = Replace(LCase$(myText), "a", "")
TrimAlpha = Replace(LCase$(myText), "b", "")
TrimAlpha = Replace(LCase$(myText), "c", "")
TrimAlpha = Replace(LCase$(myText), "d", "")
TrimAlpha = Replace(LCase$(myText), "e", "")
TrimAlpha = Replace(LCase$(myText), "f", "")
TrimAlpha = Replace(LCase$(myText), "g", "")
TrimAlpha = Replace(LCase$(myText), "h", "")
TrimAlpha = Replace(LCase$(myText), "i", "")
TrimAlpha = Replace(LCase$(myText), "j", "")
TrimAlpha = Replace(LCase$(myText), "k", "")
TrimAlpha = Replace(LCase$(myText), "l", "")
TrimAlpha = Replace(LCase$(myText), "m", "")
TrimAlpha = Replace(LCase$(myText), "n", "")
TrimAlpha = Replace(LCase$(myText), "o", "")
TrimAlpha = Replace(LCase$(myText), "p", "")
TrimAlpha = Replace(LCase$(myText), "q", "")
TrimAlpha = Replace(LCase$(myText), "r", "")
TrimAlpha = Replace(LCase$(myText), "s", "")
TrimAlpha = Replace(LCase$(myText), "t", "")
TrimAlpha = Replace(LCase$(myText), "u", "")
TrimAlpha = Replace(LCase$(myText), "v", "")
TrimAlpha = Replace(LCase$(myText), "w", "")
TrimAlpha = Replace(LCase$(myText), "x", "")
TrimAlpha = Replace(LCase$(myText), "y", "")
TrimAlpha = Replace(LCase$(myText), "z", "")
TrimAlpha = TrimAlpha
End Function
Private Function GetHex() As String
Randomize
GetHex = ShowHex(Rnd * 101, 2)
End Function
Private Function ShowHex(ByVal Number As Long, Optional Digits As Integer = 2)
ShowHex = Right$(String$(Digits, "0") & Hex$(Number), Digits)
End Function
Public Function GenHex0(MySymbol As String) As String
On Error Resume Next
GenHex0 = GetHex & MySymbol & GetHex & MySymbol & GetHex
End Function
Public Function GenHex1() As String 'generate with hardcode 00's and semicolons
GenHex1 = "00:" & GetHex & ":" & GetHex & ":" & GetHex & ":" & GetHex & ":" & GetHex
End Function
Public Function GenHex2() As String 'generate with hardcode 00's and no semi
GenHex2 = "00" & GetHex & GetHex & GetHex & GetHex & GetHex
End Function
Public Function GenHex3() As String 'generate without hardcode 00's and with semicolons
GenHex3 = GetHex & ":" & GetHex & ":" & GetHex & ":" & GetHex & ":" & GetHex & ":" & GetHex
End Function
Public Function GenHex4() As String 'generate without hardcode 00's and no semicolons
GenHex4 = GetHex & GetHex & GetHex & GetHex & GetHex & GetHex
End Function

Public Function SearchBox(ByVal SearchTerm As String, ByVal MyLB As ListBox, ByVal myLB2 As ListBox) As Boolean
On Error Resume Next
Dim i As Integer
For i = 0 To Len(MyLB)
    Dim lngListIndex As Long
    
    lngListIndex = SendMessage(MyLB.hwnd, LB_FINDSTRINGEXACT, -1, ByVal SearchTerm)
    If lngListIndex = -1 Then
        SearchBox = True
    Else
    SearchBox = False
    Exit Function
    
End If
Next i
DoEvents
End Function

Public Function cleanList(ByVal myList As ListBox, ByVal toList As ListBox, ByVal fndTxt As String, ByVal replaceTxt As String)
Dim Item() As String
Dim i As Long
Dim myData As String
i = 0
For i = 0 To myList.ListCount - 1
    ReDim Preserve Item(i)
    Item(i) = myList.List(i)
    myList.ListIndex = i
    myData = CStr(Replace(myList.Text, CStr(fndTxt), CStr(replaceTxt)))
    toList.AddItem myData
    DoEvents
Next i
myList.ListIndex = myList.ListIndex + 1
End Function
